package com.vm.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.vm.activity.ActiveActivity;
import com.vm.adapter.CategoryAppGridAdapter.ViewHolder;
import com.vm.commons.StringUtil;
import com.vm.commons.VMConst;
import com.vm.model.AppType;
import com.wwt.app.R;

public class CategoryAppGridAdapter extends BaseAdapter {

	private Context mContext;
	private List<AppType> gridtypes;

	/**
	 * 
	 */
	public CategoryAppGridAdapter(Context context, List<AppType> gridtypes) {
		this.mContext = context;
		this.gridtypes = gridtypes;

		RequestQueue requestQueue = Volley.newRequestQueue(context);

	}

	@Override
	public int getCount() {
		return gridtypes.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder = null;
		if (convertView == null) {

			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.category_apply_small_item, null);
			viewHolder = new ViewHolder();

			viewHolder.btn_small_category = (Button) convertView
					.findViewById(R.id.btn_small_category);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		final AppType gridtype = gridtypes.get(position);
		if (position == 0) {
			viewHolder.btn_small_category
					.setBackgroundResource(R.drawable.category_border_left);
		}

		viewHolder.btn_small_category.setTag(gridtype.getId());
		viewHolder.btn_small_category.setText(gridtype.getName());
		viewHolder.btn_small_category.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				gridtype.getId();
				Intent intent = new Intent(v.getContext(), ActiveActivity.class);
				intent.putExtra("activeType", "getSoftByType?typeId="
						+ gridtype.getId());
				intent.putExtra("currentType", gridtype.getName());
				v.getContext().startActivity(intent);

			}
		});
		// Log.i("TEST", (String) viewHolder.btn_small_category.getText());

		return convertView;

	}

	static class ViewHolder {
		Button btn_small_category;

	}

}
